package org.jeecg.modules.pdd.util;

import cn.hutool.http.HttpUtil;
import com.pdd.pop.sdk.http.PopClient;
import com.pdd.pop.sdk.http.PopHttpClient;
import com.pdd.pop.sdk.http.api.pop.request.PddDdkGoodsPidGenerateRequest;
import com.pdd.pop.sdk.http.api.pop.request.PddDdkGoodsPidQueryRequest;
import com.pdd.pop.sdk.http.api.pop.response.PddDdkGoodsPidGenerateResponse;
import com.pdd.pop.sdk.http.api.pop.response.PddDdkGoodsPidQueryResponse;
import org.jeecg.common.util.mall.HttpUtils;
import org.jeecg.modules.pdd.config.PddConfig;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class PddUtil {


    public static  List<PddDdkGoodsPidGenerateResponse.PIdGenerateResponsePIdListItem> createPid(String pid_str) throws Exception {

        PopClient client = new PopHttpClient(PddConfig.APP_KEY, PddConfig.APP_SECRET);
        PddDdkGoodsPidGenerateRequest request = new PddDdkGoodsPidGenerateRequest();
        request.setNumber(1L);
        List<String> pIdNameList = new ArrayList<>();
        pIdNameList.add(pid_str);
        request.setPIdNameList(pIdNameList);
        PddDdkGoodsPidGenerateResponse response = client.syncInvoke(request);
        Integer remainpidcount=  response.getPIdGenerateResponse().getRemainPidCount();
        if(null==remainpidcount){
            return null;
        }
        List<PddDdkGoodsPidGenerateResponse.PIdGenerateResponsePIdListItem> listItemList=response.getPIdGenerateResponse().getPIdList();

        String  pid=listItemList.get(0).getPId();
        String pidName= listItemList.get(0).getPidName();
        return listItemList;
    }

    public static PddDdkGoodsPidQueryResponse.PIdQueryResponse getPid(int page,int pageSize) throws Exception {
        PopClient client = new PopHttpClient(PddConfig.APP_KEY, PddConfig.APP_SECRET);
        PddDdkGoodsPidQueryRequest request = new PddDdkGoodsPidQueryRequest();
        request.setPage(2);
        request.setPageSize(100);
        PddDdkGoodsPidQueryResponse response = client.syncInvoke(request);
        System.out.println(response.getPIdQueryResponse().getTotalCount());
        return response.getPIdQueryResponse();
    }

    public static void main(String[] args) throws Exception {
     //   createPid("1_5");
        //getPid();

    }
}
